<?php


abstract class BaseKernelMenu extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $id;

	
	protected $menu_id;

	
	protected $icono_id;

	
	protected $nombre;

	
	protected $accion;

	
	protected $destino;

	
	protected $nivel;

	
	protected $aKernelMenuRelatedByMenuId;

	
	protected $aKernelIcono;

	
	protected $collKernelMenusRelatedByMenuId;

	
	private $lastKernelMenuRelatedByMenuIdCriteria = null;

	
	protected $collKernelMenuGrupos;

	
	private $lastKernelMenuGrupoCriteria = null;

	
	protected $collKernelMenuUsuarios;

	
	private $lastKernelMenuUsuarioCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function __construct()
	{
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
		$this->nivel = 1;
	}

	
	public function getId()
	{
		return $this->id;
	}

	
	public function getMenuId()
	{
		return $this->menu_id;
	}

	
	public function getIconoId()
	{
		return $this->icono_id;
	}

	
	public function getNombre()
	{
		return $this->nombre;
	}

	
	public function getAccion()
	{
		return $this->accion;
	}

	
	public function getDestino()
	{
		return $this->destino;
	}

	
	public function getNivel()
	{
		return $this->nivel;
	}

	
	public function setId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = KernelMenuPeer::ID;
		}

		return $this;
	} 
	
	public function setMenuId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->menu_id !== $v) {
			$this->menu_id = $v;
			$this->modifiedColumns[] = KernelMenuPeer::MENU_ID;
		}

		if ($this->aKernelMenuRelatedByMenuId !== null && $this->aKernelMenuRelatedByMenuId->getId() !== $v) {
			$this->aKernelMenuRelatedByMenuId = null;
		}

		return $this;
	} 
	
	public function setIconoId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->icono_id !== $v) {
			$this->icono_id = $v;
			$this->modifiedColumns[] = KernelMenuPeer::ICONO_ID;
		}

		if ($this->aKernelIcono !== null && $this->aKernelIcono->getId() !== $v) {
			$this->aKernelIcono = null;
		}

		return $this;
	} 
	
	public function setNombre($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->nombre !== $v) {
			$this->nombre = $v;
			$this->modifiedColumns[] = KernelMenuPeer::NOMBRE;
		}

		return $this;
	} 
	
	public function setAccion($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->accion !== $v) {
			$this->accion = $v;
			$this->modifiedColumns[] = KernelMenuPeer::ACCION;
		}

		return $this;
	} 
	
	public function setDestino($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->destino !== $v) {
			$this->destino = $v;
			$this->modifiedColumns[] = KernelMenuPeer::DESTINO;
		}

		return $this;
	} 
	
	public function setNivel($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->nivel !== $v || $v === 1) {
			$this->nivel = $v;
			$this->modifiedColumns[] = KernelMenuPeer::NIVEL;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(KernelMenuPeer::NIVEL))) {
				return false;
			}

			if ($this->nivel !== 1) {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->menu_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
			$this->icono_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
			$this->nombre = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->accion = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->destino = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->nivel = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 7; 
		} catch (Exception $e) {
			throw new PropelException("Error populating KernelMenu object", $e);
		}
	}

	
	public function ensureConsistency()
	{

		if ($this->aKernelMenuRelatedByMenuId !== null && $this->menu_id !== $this->aKernelMenuRelatedByMenuId->getId()) {
			$this->aKernelMenuRelatedByMenuId = null;
		}
	
		if ($this->aKernelIcono !== null && $this->icono_id !== $this->aKernelIcono->getId()) {
			$this->aKernelIcono = null;
		}
	
	} 
	
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(KernelMenuPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = KernelMenuPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); 
		if ($deep) {  
			$this->aKernelMenuRelatedByMenuId = null;
			$this->aKernelIcono = null;
			$this->collKernelMenusRelatedByMenuId = null;
			$this->lastKernelMenuRelatedByMenuIdCriteria = null;

			$this->collKernelMenuGrupos = null;
			$this->lastKernelMenuGrupoCriteria = null;

			$this->collKernelMenuUsuarios = null;
			$this->lastKernelMenuUsuarioCriteria = null;

		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(KernelMenuPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		try {
			$con->beginTransaction();
			KernelMenuPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(KernelMenuPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		try {
		    if($this->validate())
		    {
    			$con->beginTransaction();
    			$affectedRows = $this->doSave($con);
    			$con->commit();
    			KernelMenuPeer::addInstanceToPool($this);
    			return true;
			}else
			{
			     
                 return false;
            }
		} catch (PropelException $e) {
			$con->rollback();
			
			
			ErrorLog::reportarError('errors', 'error',  $e->getMessage() );
			return false;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

												
			if ($this->aKernelMenuRelatedByMenuId !== null) {
				if ($this->aKernelMenuRelatedByMenuId->isModified() || $this->aKernelMenuRelatedByMenuId->isNew()) {
					$affectedRows += $this->aKernelMenuRelatedByMenuId->save($con);
				}
				$this->setKernelMenuRelatedByMenuId($this->aKernelMenuRelatedByMenuId);
			}

			if ($this->aKernelIcono !== null) {
				if ($this->aKernelIcono->isModified() || $this->aKernelIcono->isNew()) {
					$affectedRows += $this->aKernelIcono->save($con);
				}
				$this->setKernelIcono($this->aKernelIcono);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = KernelMenuPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += KernelMenuPeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			if ($this->collKernelMenusRelatedByMenuId !== null) {
				foreach ($this->collKernelMenusRelatedByMenuId as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collKernelMenuGrupos !== null) {
				foreach ($this->collKernelMenuGrupos as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collKernelMenuUsuarios !== null) {
				foreach ($this->collKernelMenuUsuarios as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aKernelMenuRelatedByMenuId !== null) {
				if (!$this->aKernelMenuRelatedByMenuId->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aKernelMenuRelatedByMenuId->getValidationFailures());
				}
			}

			if ($this->aKernelIcono !== null) {
				if (!$this->aKernelIcono->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aKernelIcono->getValidationFailures());
				}
			}


			if (($retval = KernelMenuPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collKernelMenusRelatedByMenuId !== null) {
					foreach ($this->collKernelMenusRelatedByMenuId as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collKernelMenuGrupos !== null) {
					foreach ($this->collKernelMenuGrupos as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collKernelMenuUsuarios !== null) {
					foreach ($this->collKernelMenuUsuarios as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = KernelMenuPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getMenuId();
				break;
			case 2:
				return $this->getIconoId();
				break;
			case 3:
				return $this->getNombre();
				break;
			case 4:
				return $this->getAccion();
				break;
			case 5:
				return $this->getDestino();
				break;
			case 6:
				return $this->getNivel();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = KernelMenuPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getMenuId(),
			$keys[2] => $this->getIconoId(),
			$keys[3] => $this->getNombre(),
			$keys[4] => $this->getAccion(),
			$keys[5] => $this->getDestino(),
			$keys[6] => $this->getNivel(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = KernelMenuPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setMenuId($value);
				break;
			case 2:
				$this->setIconoId($value);
				break;
			case 3:
				$this->setNombre($value);
				break;
			case 4:
				$this->setAccion($value);
				break;
			case 5:
				$this->setDestino($value);
				break;
			case 6:
				$this->setNivel($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = KernelMenuPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setMenuId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setIconoId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setNombre($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setAccion($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setDestino($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setNivel($arr[$keys[6]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);

		if ($this->isColumnModified(KernelMenuPeer::ID)) $criteria->add(KernelMenuPeer::ID, $this->id);
		if ($this->isColumnModified(KernelMenuPeer::MENU_ID)) $criteria->add(KernelMenuPeer::MENU_ID, $this->menu_id);
		if ($this->isColumnModified(KernelMenuPeer::ICONO_ID)) $criteria->add(KernelMenuPeer::ICONO_ID, $this->icono_id);
		if ($this->isColumnModified(KernelMenuPeer::NOMBRE)) $criteria->add(KernelMenuPeer::NOMBRE, $this->nombre);
		if ($this->isColumnModified(KernelMenuPeer::ACCION)) $criteria->add(KernelMenuPeer::ACCION, $this->accion);
		if ($this->isColumnModified(KernelMenuPeer::DESTINO)) $criteria->add(KernelMenuPeer::DESTINO, $this->destino);
		if ($this->isColumnModified(KernelMenuPeer::NIVEL)) $criteria->add(KernelMenuPeer::NIVEL, $this->nivel);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);

		$criteria->add(KernelMenuPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setMenuId($this->menu_id);

		$copyObj->setIconoId($this->icono_id);

		$copyObj->setNombre($this->nombre);

		$copyObj->setAccion($this->accion);

		$copyObj->setDestino($this->destino);

		$copyObj->setNivel($this->nivel);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach ($this->getKernelMenusRelatedByMenuId() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addKernelMenuRelatedByMenuId($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getKernelMenuGrupos() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addKernelMenuGrupo($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getKernelMenuUsuarios() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addKernelMenuUsuario($relObj->copy($deepCopy));
				}
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new KernelMenuPeer();
		}
		return self::$peer;
	}

	
	public function setKernelMenuRelatedByMenuId(KernelMenu $v = null)
	{
		if ($v === null) {
			$this->setMenuId(NULL);
		} else {
			$this->setMenuId($v->getId());
		}

		$this->aKernelMenuRelatedByMenuId = $v;

						if ($v !== null) {
			$v->addKernelMenuRelatedByMenuId($this);
		}

		return $this;
	}


	
	public function getKernelMenuRelatedByMenuId(PropelPDO $con = null)
	{
		if ($this->aKernelMenuRelatedByMenuId === null && ($this->menu_id !== null)) {
			$this->aKernelMenuRelatedByMenuId = KernelMenuPeer::retrieveByPK($this->menu_id, $con);
			
		}
		return $this->aKernelMenuRelatedByMenuId;
	}

	
	public function setKernelIcono(KernelIcono $v = null)
	{
		if ($v === null) {
			$this->setIconoId(NULL);
		} else {
			$this->setIconoId($v->getId());
		}

		$this->aKernelIcono = $v;

						if ($v !== null) {
			$v->addKernelMenu($this);
		}

		return $this;
	}


	
	public function getKernelIcono(PropelPDO $con = null)
	{
		if ($this->aKernelIcono === null && ($this->icono_id !== null)) {
			$this->aKernelIcono = KernelIconoPeer::retrieveByPK($this->icono_id, $con);
			
		}
		return $this->aKernelIcono;
	}

	
	public function clearKernelMenusRelatedByMenuId()
	{
		$this->collKernelMenusRelatedByMenuId = null; 	}

	
	public function getKernelMenusRelatedByMenuId($criteria = null, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collKernelMenusRelatedByMenuId === null) {
			if ($this->isNew()) {
			   $this->collKernelMenusRelatedByMenuId = array();
			} else {

				$criteria->add(KernelMenuPeer::MENU_ID, $this->getId());

				KernelMenuPeer::addSelectColumns($criteria);
				$this->collKernelMenusRelatedByMenuId = KernelMenuPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(KernelMenuPeer::MENU_ID, $this->getId());

				KernelMenuPeer::addSelectColumns($criteria);
				if (!isset($this->lastKernelMenuRelatedByMenuIdCriteria) || !$this->lastKernelMenuRelatedByMenuIdCriteria->equals($criteria)) {
					$this->collKernelMenusRelatedByMenuId = KernelMenuPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastKernelMenuRelatedByMenuIdCriteria = $criteria;
		return $this->collKernelMenusRelatedByMenuId;
	}

	
	public function countKernelMenusRelatedByMenuId(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collKernelMenusRelatedByMenuId === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(KernelMenuPeer::MENU_ID, $this->getId());

				$count = KernelMenuPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(KernelMenuPeer::MENU_ID, $this->getId());

				if (!isset($this->lastKernelMenuRelatedByMenuIdCriteria) || !$this->lastKernelMenuRelatedByMenuIdCriteria->equals($criteria)) {
					$count = KernelMenuPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collKernelMenusRelatedByMenuId);
				}
			} else {
				$count = count($this->collKernelMenusRelatedByMenuId);
			}
		}
		$this->lastKernelMenuRelatedByMenuIdCriteria = $criteria;
		return $count;
	}

	
	public function addKernelMenuRelatedByMenuId(KernelMenu $l)
	{
		if ($this->collKernelMenusRelatedByMenuId === null) {
			$this->collKernelMenusRelatedByMenuId = array();
		}
		if (!in_array($l, $this->collKernelMenusRelatedByMenuId, true)) { 			array_push($this->collKernelMenusRelatedByMenuId, $l);
			$l->setKernelMenuRelatedByMenuId($this);
		}
	}


	
	public function getKernelMenusRelatedByMenuIdJoinKernelIcono($criteria = null, $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collKernelMenusRelatedByMenuId === null) {
			if ($this->isNew()) {
				$this->collKernelMenusRelatedByMenuId = array();
			} else {

				$criteria->add(KernelMenuPeer::MENU_ID, $this->getId());

				$this->collKernelMenusRelatedByMenuId = KernelMenuPeer::doSelectJoinKernelIcono($criteria, $con);
			}
		} else {
									
			$criteria->add(KernelMenuPeer::MENU_ID, $this->getId());

			if (!isset($this->lastKernelMenuRelatedByMenuIdCriteria) || !$this->lastKernelMenuRelatedByMenuIdCriteria->equals($criteria)) {
				$this->collKernelMenusRelatedByMenuId = KernelMenuPeer::doSelectJoinKernelIcono($criteria, $con);
			}
		}
		$this->lastKernelMenuRelatedByMenuIdCriteria = $criteria;

		return $this->collKernelMenusRelatedByMenuId;
	}

	
	public function clearKernelMenuGrupos()
	{
		$this->collKernelMenuGrupos = null; 	}

	
	public function getKernelMenuGrupos($criteria = null, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collKernelMenuGrupos === null) {
			if ($this->isNew()) {
			   $this->collKernelMenuGrupos = array();
			} else {

				$criteria->add(KernelMenuGrupoPeer::MENU_ID, $this->getId());

				KernelMenuGrupoPeer::addSelectColumns($criteria);
				$this->collKernelMenuGrupos = KernelMenuGrupoPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(KernelMenuGrupoPeer::MENU_ID, $this->getId());

				KernelMenuGrupoPeer::addSelectColumns($criteria);
				if (!isset($this->lastKernelMenuGrupoCriteria) || !$this->lastKernelMenuGrupoCriteria->equals($criteria)) {
					$this->collKernelMenuGrupos = KernelMenuGrupoPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastKernelMenuGrupoCriteria = $criteria;
		return $this->collKernelMenuGrupos;
	}

	
	public function countKernelMenuGrupos(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collKernelMenuGrupos === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(KernelMenuGrupoPeer::MENU_ID, $this->getId());

				$count = KernelMenuGrupoPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(KernelMenuGrupoPeer::MENU_ID, $this->getId());

				if (!isset($this->lastKernelMenuGrupoCriteria) || !$this->lastKernelMenuGrupoCriteria->equals($criteria)) {
					$count = KernelMenuGrupoPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collKernelMenuGrupos);
				}
			} else {
				$count = count($this->collKernelMenuGrupos);
			}
		}
		$this->lastKernelMenuGrupoCriteria = $criteria;
		return $count;
	}

	
	public function addKernelMenuGrupo(KernelMenuGrupo $l)
	{
		if ($this->collKernelMenuGrupos === null) {
			$this->collKernelMenuGrupos = array();
		}
		if (!in_array($l, $this->collKernelMenuGrupos, true)) { 			array_push($this->collKernelMenuGrupos, $l);
			$l->setKernelMenu($this);
		}
	}


	
	public function getKernelMenuGruposJoinKernelGrupo($criteria = null, $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collKernelMenuGrupos === null) {
			if ($this->isNew()) {
				$this->collKernelMenuGrupos = array();
			} else {

				$criteria->add(KernelMenuGrupoPeer::MENU_ID, $this->getId());

				$this->collKernelMenuGrupos = KernelMenuGrupoPeer::doSelectJoinKernelGrupo($criteria, $con);
			}
		} else {
									
			$criteria->add(KernelMenuGrupoPeer::MENU_ID, $this->getId());

			if (!isset($this->lastKernelMenuGrupoCriteria) || !$this->lastKernelMenuGrupoCriteria->equals($criteria)) {
				$this->collKernelMenuGrupos = KernelMenuGrupoPeer::doSelectJoinKernelGrupo($criteria, $con);
			}
		}
		$this->lastKernelMenuGrupoCriteria = $criteria;

		return $this->collKernelMenuGrupos;
	}

	
	public function clearKernelMenuUsuarios()
	{
		$this->collKernelMenuUsuarios = null; 	}

	
	public function getKernelMenuUsuarios($criteria = null, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collKernelMenuUsuarios === null) {
			if ($this->isNew()) {
			   $this->collKernelMenuUsuarios = array();
			} else {

				$criteria->add(KernelMenuUsuarioPeer::MENU_ID, $this->getId());

				KernelMenuUsuarioPeer::addSelectColumns($criteria);
				$this->collKernelMenuUsuarios = KernelMenuUsuarioPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(KernelMenuUsuarioPeer::MENU_ID, $this->getId());

				KernelMenuUsuarioPeer::addSelectColumns($criteria);
				if (!isset($this->lastKernelMenuUsuarioCriteria) || !$this->lastKernelMenuUsuarioCriteria->equals($criteria)) {
					$this->collKernelMenuUsuarios = KernelMenuUsuarioPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastKernelMenuUsuarioCriteria = $criteria;
		return $this->collKernelMenuUsuarios;
	}

	
	public function countKernelMenuUsuarios(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collKernelMenuUsuarios === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(KernelMenuUsuarioPeer::MENU_ID, $this->getId());

				$count = KernelMenuUsuarioPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(KernelMenuUsuarioPeer::MENU_ID, $this->getId());

				if (!isset($this->lastKernelMenuUsuarioCriteria) || !$this->lastKernelMenuUsuarioCriteria->equals($criteria)) {
					$count = KernelMenuUsuarioPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collKernelMenuUsuarios);
				}
			} else {
				$count = count($this->collKernelMenuUsuarios);
			}
		}
		$this->lastKernelMenuUsuarioCriteria = $criteria;
		return $count;
	}

	
	public function addKernelMenuUsuario(KernelMenuUsuario $l)
	{
		if ($this->collKernelMenuUsuarios === null) {
			$this->collKernelMenuUsuarios = array();
		}
		if (!in_array($l, $this->collKernelMenuUsuarios, true)) { 			array_push($this->collKernelMenuUsuarios, $l);
			$l->setKernelMenu($this);
		}
	}


	
	public function getKernelMenuUsuariosJoinKernelUsuario($criteria = null, $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collKernelMenuUsuarios === null) {
			if ($this->isNew()) {
				$this->collKernelMenuUsuarios = array();
			} else {

				$criteria->add(KernelMenuUsuarioPeer::MENU_ID, $this->getId());

				$this->collKernelMenuUsuarios = KernelMenuUsuarioPeer::doSelectJoinKernelUsuario($criteria, $con);
			}
		} else {
									
			$criteria->add(KernelMenuUsuarioPeer::MENU_ID, $this->getId());

			if (!isset($this->lastKernelMenuUsuarioCriteria) || !$this->lastKernelMenuUsuarioCriteria->equals($criteria)) {
				$this->collKernelMenuUsuarios = KernelMenuUsuarioPeer::doSelectJoinKernelUsuario($criteria, $con);
			}
		}
		$this->lastKernelMenuUsuarioCriteria = $criteria;

		return $this->collKernelMenuUsuarios;
	}


	
	public function getKernelMenuUsuariosJoinKernelGrupo($criteria = null, $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(KernelMenuPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collKernelMenuUsuarios === null) {
			if ($this->isNew()) {
				$this->collKernelMenuUsuarios = array();
			} else {

				$criteria->add(KernelMenuUsuarioPeer::MENU_ID, $this->getId());

				$this->collKernelMenuUsuarios = KernelMenuUsuarioPeer::doSelectJoinKernelGrupo($criteria, $con);
			}
		} else {
									
			$criteria->add(KernelMenuUsuarioPeer::MENU_ID, $this->getId());

			if (!isset($this->lastKernelMenuUsuarioCriteria) || !$this->lastKernelMenuUsuarioCriteria->equals($criteria)) {
				$this->collKernelMenuUsuarios = KernelMenuUsuarioPeer::doSelectJoinKernelGrupo($criteria, $con);
			}
		}
		$this->lastKernelMenuUsuarioCriteria = $criteria;

		return $this->collKernelMenuUsuarios;
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			foreach($this->collKernelMenusRelatedByMenuId as $o) {
				$o->clearAllReferences($deep);
			}
			foreach($this->collKernelMenuGrupos as $o) {
				$o->clearAllReferences($deep);
			}
			foreach($this->collKernelMenuUsuarios as $o) {
				$o->clearAllReferences($deep);
			}
		} 
		$this->collKernelMenusRelatedByMenuId = null;
		$this->collKernelMenuGrupos = null;
		$this->collKernelMenuUsuarios = null;
	}

} 